package com.yyqx.web_maven.controller;

import com.yyqx.web_maven.dao.UsersDao;
import com.yyqx.web_maven.entity.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "UsersServlet",urlPatterns = "/UsersServlet")
public class UsersServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UsersDao dao = new UsersDao();
        List<Users> list = new ArrayList<Users>();
        try{
            list = dao.getList();
        }catch (Exception e){
            e.printStackTrace();

        }

        System.out.println(list.size());



        request.setAttribute("list",list);

        request.getRequestDispatcher("list.jsp").forward(request,response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);

    }
}
